﻿namespace HRM.CORE
{
    using DevExpress.XtraEditors;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;

    using System; using Extra.ERP;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Threading;
    using System.Windows.Forms; using Common;
    using APP.HELPER.Data.Helper;

    public class HRM_SALARY_PAY
    {
        private System.DateTime m_Date;
        private string m_Description;
        private string m_EmployeeCode;
        private decimal m_Money;
        private int m_Order;
        private decimal m_PayMoney;
        private string m_Person;
        private decimal m_RealMoney;
        private string m_Reason;
        private Guid m_SalaryPayID;
        private Guid m_SalaryTableListID;

        public HRM_SALARY_PAY()
        {
            this.m_SalaryTableListID = Guid.Empty;
            this.m_EmployeeCode = "";
            this.m_SalaryPayID = Guid.Empty;
            this.m_Order = 0;
            this.m_Reason = "";
            this.m_Date = System.DateTime.Now;
            this.m_Money = 0M;
            this.m_PayMoney = 0M;
            this.m_RealMoney = 0M;
            this.m_Person = "";
            this.m_Description = "";
        }

        public HRM_SALARY_PAY(Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            this.m_SalaryTableListID = SalaryTableListID;
            this.m_EmployeeCode = EmployeeCode;
            this.m_SalaryPayID = SalaryPayID;
            this.m_Order = Order;
            this.m_Reason = Reason;
            this.m_Date = Date;
            this.m_Money = Money;
            this.m_PayMoney = PayMoney;
            this.m_RealMoney = RealMoney;
            this.m_Person = Person;
            this.m_Description = Description;
        }

        public static string Create(string SalaryTableListID, string EmployeeCode, int Order, System.DateTime Date, int PayType, double Value, string Person, string Description, bool IsSkip)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@Order", "@Date", "@PayType", "@Value", "@Person", "@Description", "@IsSkip" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, Order, Date, PayType, Value, Person, Description, IsSkip };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Create", myParams, myValues);
        }

        public static string Create(int Level, string Code, string SalaryTableListID, int Order, System.DateTime Date, int PayType, double Value, string Person, string Description, bool IsSkip)
        {
            HRM_SALARY_TABLELIST hrm_salary_tablelist = new HRM_SALARY_TABLELIST();
            hrm_salary_tablelist.GetByID(new Guid(SalaryTableListID));
            int year = hrm_salary_tablelist.Year;
            int month = hrm_salary_tablelist.Month;
            System.DateTime dayFirstMonth = new System.DateTime(year, month, 1);
            System.DateTime dayEndMonth = new System.DateTime(year, month, System.DateTime.DaysInMonth(year, month));
            HRM_EMPLOYEE hrm_employee = new HRM_EMPLOYEE();
            IEnumerator enumerator = hrm_employee.GetCompactList(Level, Code, 1, dayFirstMonth, dayEndMonth).Rows.GetEnumerator();
            {
                ThreadStart start = null;
                DataRow dr;
                while (enumerator.MoveNext())
                {
                    dr = (DataRow) enumerator.Current;
                    Options.SetWaitDialogCaption("Đang cập nhật..." + dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " (" + dr["EmployeeCode"].ToString() + ")");
                    if (start == null)
                    {
                        start = delegate {
                            Create(SalaryTableListID, dr["EmployeeCode"].ToString(), Order, Date, PayType, Value, Person, Description, IsSkip);
                        };
                    }
                    Thread thread = new Thread(start);
                    thread.Start();
                    thread.Join();
                }
            }
            Options.HideDialog();
            return "OK";
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode" };
            object[] myValues = new object[] { this.m_SalaryTableListID, this.m_EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_DeleteBy", myParams, myValues);
        }

        public string Delete(Guid SalaryTableListID, string EmployeeCode)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_DeleteBy", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, Guid SalaryTableListID, string EmployeeCode)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_SALARY_PAY_DeleteBy", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, Guid SalaryTableListID, string EmployeeCode)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_SALARY_PAY_DeleteBy", myParams, myValues);
        }

        public string Delete(Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Delete", myParams, myValues);
        }

        private void DispError(object sender, SqlHelperException e)
        {
            XtraMessageBox.Show(e.Message, "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public bool Exist(Guid SalaryTableListID, string EmployeeCode, string SalaryPayID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_SALARY_PAY_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(Guid SalaryTableListID, string EmployeeCode, string SalaryPayID)
        {
            string str = "";
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("HRM_SALARY_PAY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SalaryTableListID = reader.GetGuid(reader.GetOrdinal("SalaryTableListID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_SalaryPayID = reader.GetGuid(reader.GetOrdinal("SalaryPayID"));
                    this.m_Order = Convert.ToInt32(reader["Order"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_PayMoney = Convert.ToDecimal(reader["PayMoney"]);
                    this.m_RealMoney = Convert.ToDecimal(reader["RealMoney"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, Guid SalaryTableListID, string EmployeeCode, string SalaryPayID)
        {
            string str = "";
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "HRM_SALARY_PAY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SalaryTableListID = reader.GetGuid(reader.GetOrdinal("SalaryTableListID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_SalaryPayID = reader.GetGuid(reader.GetOrdinal("SalaryPayID"));
                    this.m_Order = Convert.ToInt32(reader["Order"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_PayMoney = Convert.ToDecimal(reader["PayMoney"]);
                    this.m_RealMoney = Convert.ToDecimal(reader["RealMoney"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, Guid SalaryTableListID, string EmployeeCode, string SalaryPayID)
        {
            string str = "";
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "HRM_SALARY_PAY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_SalaryTableListID = reader.GetGuid(reader.GetOrdinal("SalaryTableListID"));
                    this.m_EmployeeCode = Convert.ToString(reader["EmployeeCode"]);
                    this.m_SalaryPayID = reader.GetGuid(reader.GetOrdinal("SalaryPayID"));
                    this.m_Order = Convert.ToInt32(reader["Order"]);
                    this.m_Reason = Convert.ToString(reader["Reason"]);
                    this.m_Date = Convert.ToDateTime(reader["Date"]);
                    this.m_Money = Convert.ToDecimal(reader["Money"]);
                    this.m_PayMoney = Convert.ToDecimal(reader["PayMoney"]);
                    this.m_RealMoney = Convert.ToDecimal(reader["RealMoney"]);
                    this.m_Person = Convert.ToString(reader["Person"]);
                    this.m_Description = Convert.ToString(reader["Description"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList(Guid SalaryTableListID, string EmployeeCode)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_SALARY_PAY_GetList1", myParams, myValues);
        }

        public DataTable GetList(int Level, string Code, Guid SalaryTableListID)
        {
            string[] myParams = new string[] { "@Level", "@Code", "@SalaryTableListID" };
            object[] myValues = new object[] { Level, Code, SalaryTableListID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_SALARY_PAY_GetList", myParams, myValues);
        }

        public DataTable GetListByOrder(int Level, string Code, Guid SalaryTableListID, int Order)
        {
            string[] myParams = new string[] { "@Level", "@Code", "@SalaryTableListID", "@Order" };
            object[] myValues = new object[] { Level, Code, SalaryTableListID, Order };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("HRM_SALARY_PAY_GetListByOrder", myParams, myValues);
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { this.m_SalaryTableListID, this.m_EmployeeCode, this.m_SalaryPayID, this.m_Order, this.m_Reason, this.m_Date, this.m_Money, this.m_PayMoney, this.m_RealMoney, this.m_Person, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { this.m_SalaryTableListID, this.m_EmployeeCode, this.m_SalaryPayID, this.m_Order, this.m_Reason, this.m_Date, this.m_Money, this.m_PayMoney, this.m_RealMoney, this.m_Person, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_SALARY_PAY_Insert", myParams, myValues);
        }

        public string Insert(Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_SALARY_PAY_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_SALARY_PAY_Insert", myParams, myValues);
        }

        public string Update()
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { this.m_SalaryTableListID, this.m_EmployeeCode, this.m_SalaryPayID, this.m_Order, this.m_Reason, this.m_Date, this.m_Money, this.m_PayMoney, this.m_RealMoney, this.m_Person, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { this.m_SalaryTableListID, this.m_EmployeeCode, this.m_SalaryPayID, this.m_Order, this.m_Reason, this.m_Date, this.m_Money, this.m_PayMoney, this.m_RealMoney, this.m_Person, this.m_Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_SALARY_PAY_Update", myParams, myValues);
        }

        public string Update(Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, this.Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("HRM_SALARY_PAY_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "HRM_SALARY_PAY_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, Guid SalaryTableListID, string EmployeeCode, Guid SalaryPayID, int Order, string Reason, System.DateTime Date, decimal Money, decimal PayMoney, decimal RealMoney, string Person, string Description)
        {
            string[] myParams = new string[] { "@SalaryTableListID", "@EmployeeCode", "@SalaryPayID", "@Order", "@Reason", "@Date", "@Money", "@PayMoney", "@RealMoney", "@Person", "@Description" };
            object[] myValues = new object[] { SalaryTableListID, EmployeeCode, SalaryPayID, Order, Reason, Date, Money, PayMoney, RealMoney, Person, Description };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "HRM_SALARY_PAY_Update", myParams, myValues);
        }

        [DisplayName("Date"), Category("Column")]
        public System.DateTime Date
        {
            get
            {
                return this.m_Date;
            }
            set
            {
                this.m_Date = value;
            }
        }

        [DisplayName("Description"), Category("Column")]
        public string Description
        {
            get
            {
                return this.m_Description;
            }
            set
            {
                this.m_Description = value;
            }
        }

        [Category("Primary Key"), DisplayName("EmployeeCode")]
        public string EmployeeCode
        {
            get
            {
                return this.m_EmployeeCode;
            }
            set
            {
                this.m_EmployeeCode = value;
            }
        }

        [DisplayName("Money"), Category("Column")]
        public decimal Money
        {
            get
            {
                return this.m_Money;
            }
            set
            {
                this.m_Money = value;
            }
        }

        [Category("Column"), DisplayName("Order")]
        public int Order
        {
            get
            {
                return this.m_Order;
            }
            set
            {
                this.m_Order = value;
            }
        }

        [DisplayName("PayMoney"), Category("Column")]
        public decimal PayMoney
        {
            get
            {
                return this.m_PayMoney;
            }
            set
            {
                this.m_PayMoney = value;
            }
        }

        [Category("Column"), DisplayName("Person")]
        public string Person
        {
            get
            {
                return this.m_Person;
            }
            set
            {
                this.m_Person = value;
            }
        }

        [Category("Column"), DisplayName("RealMoney")]
        public decimal RealMoney
        {
            get
            {
                return this.m_RealMoney;
            }
            set
            {
                this.m_RealMoney = value;
            }
        }

        [Category("Column"), DisplayName("Reason")]
        public string Reason
        {
            get
            {
                return this.m_Reason;
            }
            set
            {
                this.m_Reason = value;
            }
        }

        [DisplayName("SalaryPayID"), Category("Primary Key")]
        public Guid SalaryPayID
        {
            get
            {
                return this.m_SalaryPayID;
            }
            set
            {
                this.m_SalaryPayID = value;
            }
        }

        [Category("Primary Key"), DisplayName("SalaryTableListID")]
        public Guid SalaryTableListID
        {
            get
            {
                return this.m_SalaryTableListID;
            }
            set
            {
                this.m_SalaryTableListID = value;
            }
        }
    }
}

